﻿/*****************************************************************//**
 * @file    FITKOCCGraphObjectModel.h
 * @brief   Graph object for TopoDS_Shape and OCC graph widget.
 *
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-06-11
 *********************************************************************/

#ifndef __FITKOCCGRAPHOBJECTMODEL_H__
#define __FITKOCCGRAPHOBJECTMODEL_H__

#include "FITKOCCGraphObject3D.h"

#include "FITKOCCGraphAdaptorAPI.h"

#include <QColor>

 // Forward declaration
class QVariant;

class TopoDS_Shape;

class FITKOCCAIS_ColoredShape;

namespace Interface
{
    class FITKAbsGeoCommand;
}

namespace Exchange
{
    struct _ShapeIndiceMap;
}

namespace Exchange
{
    /**
     * @brief   Graph object for TopoDS_Shape and OCC graph widget.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-06-06
     */
    class FITKOCCGRAPHADAPTORAPI FITKOCCGraphObjectModel : public FITKOCCGraphObject3D
    {
        // Regist
        FITKGraphObjectRegist(FITKOCCGraphObjectModel, FITKOCCGraphObject3D);
        FITKCLASS(Exchange, FITKOCCGraphObjectModel);

    public:
        /**
         * @brief   Constructor.
         * @param   modelData: The model data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-11
         */
        FITKOCCGraphObjectModel(Interface::FITKAbsGeoCommand* modelData);

        /**
         * @brief   Destructor.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-06
         */
        virtual ~FITKOCCGraphObjectModel();

        /**
         * @brief   Get the visibility from the data object.[virtual][override]
         * @return  The visibility
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-09-06
         */
        virtual bool getDataVisibility() override;

        /**
         * @brief   Update the graph object.[override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-06
         */
        void update(bool forceUpdate = false) override;

        /**
         * @brief   Update the interactive objects in graph object.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-09
         */
        void updateInteractiveObjs() override;

        /**
         * @brief   Get the index with the shape data and shape type.[override]
         * @param   type: The shape type
         * @param   shape: The shape data[quote]
         * @return  The index of the shape
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-05
         */
        int getShapeIndex(FITKOCCCommons::ShapeMeshType type, TopoDS_Shape & shape) override;

        /**
         * @brief   Get the shape with the index and shape type.[override]
         * @param   type: The shape type
         * @param   index: The index of the shape
         * @return  The shape belonged to the given index
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-05
         */
        TopoDS_Shape getIndexedShape(FITKOCCCommons::ShapeMeshType type, int index) override;

        /**
         * @brief   Show or hide the shape by the given type and flag.[override]
         * @param   type: The shape type
         * @param   visible: The visibility
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-14
         */
        void setViewMode(FITKOCCCommons::ShapeMeshViewMode type, bool visible) override;

        /**
         * @brief   Set the color for single edge, face or solid.[override]
         * @param   color: The color
         * @param   type: The shape mesh type
         * @param   index: The index of solid or edge or face or solid
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-13
         */
        void setColor(QColor color, FITKOCCCommons::ShapeMeshType type, int index) override;

        /**
         * @brief   Set the color for edges, faces or solids.[override]
         * @param   color: The color
         * @param   type: The shape mesh type
         * @param   indice: The indice of edges or faces or solids
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-14
         */
        void setColor(QColor color, FITKOCCCommons::ShapeMeshType type, QList<int> indice) override;

        /**
         * @brief   Set the color to all vertice, edges and faces.[override]
         * @param   color: The color
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-13
         */
        void setColor(QColor color) override;

        /**
         * @brief   Enable or disable transparency.[override]
         * @param   isOn: Enable or not
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-05
         */
        void setEnableTransparency(bool isOn) override;

        /**
         * @brief   Set the shape of point mark.[virtual]
         * @param   type: The type of the point mark
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-20
         */
        void setPointMark(FITKOCCCommons::PointMarkShape type) override;

        /**
         * @brief   Set the point size of vertice' marks.[override]
         * @param   factor: The size factor( default 1.0 )
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-20
         */
        void setPointSizeScale(double factor) override;

        /**
         * @brief   Set the line width of the edges( wire ).[override]
         * @param   size
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-20
         */
        void setLineWidth(double size) override;

        /**
         * @brief   Highlight the whole object.[override]
         * @param   update: Need to update the view[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-07
         */
        void highlight(bool update = true) override;

        /**
         * @brief   Dis-highlight the object.[override]
         * @param   update: Need to update the view[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-07
         */
        void disHighlight(bool update = true) override;

        /**
         * @brief   Hide or show the graph object's interactive objects.[override]
         * @param   visibility: The visibility.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-05
         */
        void setVisible(bool visibility) override;

        /**
         * @brief   Set the select mode for this graph object's interactive objects.[virtual][override]
         * @param   mode: The select mode
         * @param   force: Force add the select mode[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-09-09
         */
        virtual void addSelectMode(CommonOCC::SelectMode mode, bool force = false) override;

        // Test function
        //@{
        /**
         * @brief   Test function.[override]
         * @param   details: The input information
         * @return  Is success
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-12
         */
        bool test(QVariant& details) override;
        //@}

    protected:
        /**
         * @brief   Constructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-06
         */
        FITKOCCGraphObjectModel() = default;

    protected:
        /**
         * @brief   Initialize.
         * @param   Is OK
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-01
         */
        bool initShapeData();

        /**
         * @brief   Generate the AIS_Shape with the TopoDS_Shape data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-12
         */
        void generateShape();

        /**
         * @brief   Initialize the indice maps with the given shape.
         * @param   shape: The shape[quote]
         * @param   indiceMap: The indice maps[quote]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-13
         */
        void initShapeIndiceMap(TopoDS_Shape& shape, _ShapeIndiceMap* indiceMap);

    protected:
        /**
         * @brief   Whether the graph object need to use the index map.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-09-02
         */
        bool m_useIndexMap = false;

        /**
         * @brief   The shape data of the model.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-12
         */
        TopoDS_Shape* m_tpShape{ nullptr };

        /**
         * @brief   The indice map for shape data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-13
         */
        _ShapeIndiceMap* m_indiceMap{ nullptr };

        /**
         * @brief   The interactive object for colored shape data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-05
         */
        FITKOCCAIS_ColoredShape* m_fAisShape{ nullptr };

        /**
         * @brief   The hash code of the shape.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-06
         */
        int m_hashCode = -1;

    };
}   // namespace Exchange

#endif // __FITKOCCGRAPHOBJECTMODEL_H__
